package com.bree.erp.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;

@NamedQueries({
	@NamedQuery(name= Price.QUERY_GET_UNITPRICE_OF_SUPPLIER, 
			query="SELECT p FROM Price p WHERE p.partUnit = :partUnit AND p.supplier = :supplier"),
	@NamedQuery(name= Price.QUERY_GET_UNITPRICE_OF_SUPPLIERS, 
			query="SELECT p FROM Price p WHERE p.partUnit = :partUnit")
})
@Entity
public class Price {
	
	public static final String QUERY_GET_UNITPRICE_OF_SUPPLIER = "getUnitPriceOfSupplier";
	public static final String QUERY_GET_UNITPRICE_OF_SUPPLIERS = "getUnitPriceOfSuppliers";
	public static final int COL_REMARKS_LEN = 255;

	@Id
	@GeneratedValue(strategy=GenerationType.SEQUENCE)
	private Long id;
	
	@ManyToOne
	private PartUnit partUnit;
	
	@OneToOne
	private Supplier supplier;
	
	private double pricePerUnit;
	
	@Column(length=COL_REMARKS_LEN)
	private String remarks;
	
	@Override
	public boolean equals(Object object) {
		
		if(object instanceof Price) {
			if(this.id != null) {
				Price that = (Price) object;
				return this.id.equals(that.id);
			}
		}
		
		return false;
	}
	
	@Override
	public int hashCode() {
		return this.id == null ? 0 : this.id.hashCode();
	}

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the partUnit
	 */
	public PartUnit getPartUnit() {
		return partUnit;
	}

	/**
	 * @param partUnit the partUnit to set
	 */
	public void setPartUnit(PartUnit partUnit) {
		this.partUnit = partUnit;
	}

	/**
	 * @return the supplier
	 */
	public Supplier getSupplier() {
		return supplier;
	}

	/**
	 * @param supplier the supplier to set
	 */
	public void setSupplier(Supplier supplier) {
		this.supplier = supplier;
	}

	/**
	 * @return the pricePerUnit
	 */
	public double getPricePerUnit() {
		return pricePerUnit;
	}

	/**
	 * @param pricePerUnit the pricePerUnit to set
	 */
	public void setPricePerUnit(double pricePerUnit) {
		this.pricePerUnit = pricePerUnit;
	}

	/**
	 * @return the remarks
	 */
	public String getRemarks() {
		return remarks;
	}

	/**
	 * @param remarks the remarks to set
	 */
	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}

}
